EXEC = ./bin/tcp_server 
OBJS = tcp_server.o main.o process.o bus_socket.o massege.o 
SRC  = tcp_server.c main.c process.c bus_socket.c massege.c 

CC = gcc
CFLAGS += -O2 -Wall
LDFLAGS +=

BUILD_MYSQL = 0

ifeq ($(BUILD_MYSQL),1)
	OBJS += database.o
	SRC  += database.c
	MYSQL_LIB = -lmysqlclient
endif 

all:$(EXEC)

$(EXEC):$(OBJS)
	@echo Building $@;
	$(CC) $(LDFLAGS) -o $@ $(OBJS) -pthread $(MYSQL_LIB)

%.o:%.c
	@echo Building $@;
	$(CC) $(CFLAGS) -c $< -o $@ -pthread $(MYSQL_LIB)

clean:
	@rm -vf $(EXEC) *.o *~

rebuild:
	clear
	$(MAKE) clean
	$(MAKE) all	